
<?php //TODO : Factoriser les select ?>
<h3 class="titreForm"><?php echo $menu['a']['desc']?></h3>
<form action="index.php" name="gothere">
<input value="on" name="a" type="hidden"/>
<table summary="Advanced form" id="searchForm">
<?php
foreach($selectArray as $key=>$value){
	// Nouvelle requête
	if (empty($_GET['a'])){
		echo '<tr><td>'.$fieldTable[$key][0].'&nbsp;:&nbsp;</td><td>';
		// Date de début et de fin
		if ($key=='yr'){
			echo ' Début ';
			echo '<select name="yr" class="inputbox">'."\n";
			echo '<option value="">&nbsp;'."</option>\n";
			foreach($$value as $value2){
				if(!empty($value2[0])){
					echo '<option value="'.$value2[0].'">'.$value2[0]."</option>\n";
				}
			}
			echo '</select>';
			echo ' Fin ';
			echo '<select name="yrEnd" class="inputbox">'."\n";
			echo '<option value="">&nbsp;'."</option>\n";
			foreach($$value as $value2){
				if(!empty($value2[0])){
					echo '<option value="'.$value2[0].'">'.$value2[0]."</option>\n";
				}
			}
			echo '</select>';
		}
		// Autres champs
		else {
			echo '<select name="'.$key.'" class="inputbox">'."\n";
			echo '<option value="">&nbsp;'."</option>\n";
			foreach($$value as $value2){
				if(!empty($value2[0])){
					$value2[0] = preg_replace ("/\&/","&amp;",$value2[0]);
					$maxlength = 140;
					if(strlen($value2[0]) > $maxlength) $value2Display=substr($value2[0],0,$maxlength).'...';
					else $value2Display = $value2[0];
					echo '<option value="'.$value2[0].'">'.$value2Display."</option>\n";
				}
			}
			echo '</select>';
		}
		echo '</td></tr>'."\n";
	}
	// Réponse à une requête
	else {
		if (!empty($_GET[$key])){
			echo '<tr><td>'.$value.'&nbsp;:&nbsp;</td><td>';
		// Ajout de la date de fin
		if ($key=='yr'){
			// Message en cas de date non valide
			if (!empty($_GET['yrEnd'])) if ($_GET['yrEnd'] < $_GET['yr']) echo '<div style="color:red;margin-bottom:0.5em;">La date de Fin est inférieure à la date de Début !<br/>Modifiez votre requête :</div>';
			echo ' Début ';
			echo '<select name="yr" class="inputbox">'."\n";
			echo '<option value="">&nbsp;'."</option>\n";
			foreach($$value as $value2){
				if(!empty($value2[0])){
					echo '<option value="'.$value2[0].'" ';
					if(isset($_GET[$key]) and $_GET[$key]==$value2[0]) echo 'selected="selected"';
					echo '>'.$value2[0]."</option>\n";
				}
			}
			echo '</select>';
			echo ' Fin ';
			echo '<select name="yrEnd" class="inputbox">'."\n";
			echo '<option value="">&nbsp;'."</option>\n";
			foreach($$value as $value2){
				if(!empty($value2[0])){
					echo '<option value="'.$value2[0].'" ';
					if(isset($_GET['yrEnd']) and $_GET['yrEnd']==$value2[0]) echo 'selected="selected"';
					echo '>'.$value2[0]."</option>\n";
				}
			}
			echo '</select>';
		}
		else {
			echo '<select name="'.$key.'" class="inputbox">'."\n";
			echo '<option value="">&nbsp;'."</option>\n";
			foreach($$value as $value2){
				if(!empty($value2[0])){
					$value2[0] = preg_replace ("/\&/","&amp;",$value2[0]);
					$maxlength = 140;
					if(strlen($value2[0]) > $maxlength) $value2Display=substr($value2[0],0,$maxlength).'...';
					else $value2Display = $value2[0];
					echo '<option value="'.$value2[0].'" ';
					if(isset($_GET[$key]) and $_GET[$key]==$value2[0]) echo 'selected="selected"';
					echo '>'.$value2Display."</option>\n";
				}
			}
			echo '</select>';
		}
		echo '</td></tr>'."\n";
		}
	}
}
?>
<tr><td></td><td><input value="Go" class="bouton" type="submit" name="action"/></td></tr>
</table>
</form>
